package com.example.sunmiv1.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.sunmiv1.R;
import com.example.sunmiv1.entity.PriceQueryBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PriceSkuInfoAdapter extends BaseAdapter {

    private Context context;
    private List<PriceQueryBean.GoodslistBean.SkuinfoBean.InfoBean> list;
    private int select;
    private ViewHolder viewHolder;

    public PriceSkuInfoAdapter(Context context, List<PriceQueryBean.GoodslistBean.SkuinfoBean.InfoBean> list) {
        this.context = context;
        this.list = list;
    }

    public void setSelect(int select) {
        this.select = select;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.price_sku_info_adapter, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if(position==select){
            viewHolder.skuInfoAdapterName.setBackgroundResource(R.drawable.member_login_sure_red);
            viewHolder.skuInfoAdapterName.setTextColor(context.getResources().getColor(R.color.white));
        }else{
            viewHolder.skuInfoAdapterName.setBackgroundResource(R.drawable.report_loss_border);
            viewHolder.skuInfoAdapterName.setTextColor(context.getResources().getColor(R.color.text_333));
        }
        viewHolder.skuInfoAdapterName.setText(list.get(position).getName());
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.skuInfo_adapter_name)
        TextView skuInfoAdapterName;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
